package com.example.myapplication.bean;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.json.JSONException;

import java.net.URI;
import java.util.List;

public class MyWebSocketClient extends WebSocketClient {

//    private Context mContext;
   //选择懒汉模式
     // private static MyWebSocketClient mInstance;


//    1. 私有构造方法
        public MyWebSocketClient(String username) {
            //开启WebSocket客户端
            super(URI.create("ws://121.36.92.128:8084/websocket/"+username));

        }
//
        //2.公开方法,返回单例对象
//        public static MyWebSocketClient getInstance(String username) {
//            //懒汉: 考虑线程安全问题, 两种方式: 1. 给方法加同步锁 synchronized, 效率低; 2. 给创建对象的代码块加同步锁
//            if (mInstance == null) {
//                synchronized (MyWebSocketClient.class) {
//                    if (mInstance == null) {
//                        mInstance = new MyWebSocketClient(username);
//                    }
//                }
//            }
//            return mInstance;
//        }
        // 原始构造方法
        //public MyWebSocketClient(URI serverUri) {
//            super(serverUri);
//        }

    //长链接开启
    @Override
    public void onOpen(ServerHandshake handshakedata) {
    }

    //消息通道收到消息
    @Override
    public void onMessage(String message) {

    }

    //长链接关闭
    @Override
    public void onClose(int code, String reason, boolean remote) {
    }

    //链接发生错误
    @Override
    public void onError(Exception ex) {
    }
}